package day4

object Test6_reduce {
  def main(args: Array[String]): Unit = {
    val arr = Array[Int](1, 3, 5, 7, 9)

    val m1 = arr.reduce( (v1:Int,v2:Int) => {
      println(s"$v1 , $v2")
      v1 + v2
    })
    println(m1)
    println("----------------------")
    var list = List(1,2,6,8)

    val x1 = list.reduce((v1,v2) => {
      v1 + v2
    })
    println(x1)

    val aaa = list.fold(5)((v1, v2) => {
      v1 + v2
    })
    println(aaa)

    println("-------------")
    val arr2 = Array[Int](1, 3, 5, 7, 9)
    val m2 = arr2.fold(22)( (a1:Int,a2:Int) => {
      println(s"${a1} , ${a2}")
      return a1 + a2
    })
    println(m2)


  }
}
